import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/components/Home.vue'
import TopicList from '@/components/TopicList.vue'
import Login from '@/components/login.vue'
import Center from '@/components/center.vue'
import Msg from '@/components/msg.vue'
import Logout from '@/components/logout.vue'
import Topic from '@/components/Topic.vue'
import User from '@/components/User.vue'
import Create from '@/components/create.vue'
import Edit from '@/components/edit.vue'
import Colloctions from '@/components/colloctions.vue'

//全局注册
Vue.use(VueRouter)
//定义路由对象数组
const routes=[
  // {
  //   path:'/',name:'home',component:Home
  // },
  {path:'/',redirect:'/topiclist/all'},//重定向路由
  {
    path:'/topiclist/:name',name:'topiclist',component:TopicList, props:true
  },
	//登录
	{path:'/login',name:'login',component:Login},
	//发表新话题
	{path:'/create',name:'create',component:Create},
	//编辑话题
	{path:'/topic/:id/edit',name:'edit',component:Edit,props:true},
	//个人中心
	{path:'/center',name:'center',component:Center},
	{path:'/user/:loginname',name:'user',component:User,props:true},
	//收藏界面
	{path:'/user/:loginname/colloctions',name:'colloctions',component:Colloctions,props:true},
	//消息通知
	{path:'/msg',name:'msg',component:Msg},
	//登出
	{path:'/logout',name:'logout',component:Logout},
	//详细信息
	{path:'/topic/:id',name:'topic',component:Topic,props:true}
]

//解决冗余问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 创建路由管理器
const router =new VueRouter({
  routes
})
// 对外输出
export default router;
